<template>
	<view>
		<view class="search-container">
			<my-search @click="gotoSearch"></my-search>
		</view>
	    <!-- 轮播图区域 -->
	    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
	      <!-- 循环渲染轮播图的 item 项 -->
	      <swiper-item v-for="(item, i) in swiperList" :key="i">
	        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
	          <!-- 动态绑定图片的 src 属性 -->
	          <image :src="item.image_src"></image>
	        </navigator>
	      </swiper-item>
	    </swiper>
		<!-- 分类区域 -->
		<view class="cate-container">
			<view v-for="(item, i) in navList" :key="i" @click="navClickHandler(item)">
				<image class="cateImg" :src="item.image_src"></image>
			</view>
		</view>
		<!-- 楼层区域 -->
		<view class="floor-container">
			<view class="floorItem" v-for="(item, i) in floorList" :key="i">
				<image class="titleImg" :src="item.floor_title.image_src"></image>
				<view class="detailImg-container">
					<navigator :url="'/subpkg/goods_list/'+item.product_list[0].navigator_url.split('/')[2]">
						<image class="leftDetailImg" :src="item.product_list[0].image_src" :style="'width: ' + item.product_list[0].image_width + 'rpx;'" mode="widthFix"></image>						
					</navigator>
					<view class="right">
						<navigator v-for="(item1, i1) in item.product_list.slice(1,5)" :key="i1" :url="'/subpkg/goods_list/'+item1.navigator_url.split('/')[2]">
							<image class="rightDetailImg" :src="item1.image_src" :style="'width: ' + item1.image_width + 'rpx;'" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	  </view>
</template>

<script>
	import tabbarBadge from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [tabbarBadge],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.meta.status !== 200) return uni.$showMsg()
				this.swiperList = res.message
			},
			async getNavList() {
				const { data: res } = await uni.$http.get('/api/public/v1/home/catitems')
				if(res.meta.status !== 200) return uni.$showMsg()
				this.navList = res.message
			},
			async getFloorList() {
				const { data: res } = await uni.$http.get('/api/public/v1/home/floordata')
				if(res.meta.status !== 200) return uni.$showMsg()
				this.floorList = res.message
			},
			navClickHandler(item) {
				if(item.name === '分类') {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
			},
			gotoSearch() {
				uni.navigateTo({
					url: "/subpkg/search/search"
				})
			}
		}
	}
</script>

<style lang="scss">
.search-container {
	position: sticky;
	top: 0;
	z-index: 999;
}
swiper {
 height: 330rpx;

 .swiper-item,
 image {
   width: 100%;
   height: 100%;
 }
}
.cate-container {
	display: flex;
	justify-content: space-around;
	margin-top: 10rpx;
	.cateImg {
		width: 128rpx;
		height: 140rpx;
	}
}
.floorItem {
	display: flex;
	flex-direction: column;
	.titleImg {
		width: 100%;
		height: 60rpx;
		margin: 20rpx 0;
	}
	.detailImg-container {
		display: flex;
		.right {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
			align-items: center;
		}
	}
}
</style>